package com.fallsvc.re.javase.string;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/13  10:17
 */
public class Demo2 {
    public static void main1(String[] args) {
        String s = "hello";
        s += " world";
        System.out.println(s);
    }
    public static void main2(String[] args) {
        long start = System.currentTimeMillis();
        String s = "";
        for(int i = 0; i < 10000; ++i){
            s += i;
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuffer sbf = new StringBuffer("");
        for(int i = 0; i < 10000; ++i){
            sbf.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);

        start = System.currentTimeMillis();
        StringBuilder sbd = new StringBuilder();
        for(int i = 0; i < 10000; ++i){
            sbd.append(i);
        }
        end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        String s = "ab";
        String str = new String("ab"); // 会创建多少个对象
        String str1 = new String("a") + new String("b"); // 会创建多少个对象
        System.out.println(str == str1);
        System.out.println(str.equals(str1));
        System.out.println(s == str);
        System.out.println(s == str1);
    }
}
